package top.jfunc.network.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiongshiyan at 2019/5/7 , contact me with email yanshixiong@126.com or phone 15208384257
 */
@RestController
@RequestMapping("/post")
public class PostController extends BaseController{
    private static final Logger logger = LoggerFactory.getLogger(PostController.class);

    @PostMapping("body")
    public String postBody(@RequestBody String body , HttpServletRequest httpServletRequest){
        printQueryString(logger , httpServletRequest);

        printParams(logger , httpServletRequest);

        printHeaders(logger , httpServletRequest);

        printBody(logger , body);

        return body;
    }
    @PostMapping("bodyGBK")
    public String postBodyGBK(@RequestBody byte[] body) throws Exception{
        return new String(body , "GBK");
    }
    @PostMapping("form")
    public String postForm(@RequestParam MultiValueMap<String, String> parameters , HttpServletRequest httpServletRequest){
        printQueryString(logger , httpServletRequest);

        printParams(logger , httpServletRequest);

        printHeaders(logger , httpServletRequest);

        parameters.forEach((k,v)->logger.info(k + "-------" + v));

        return "success";
    }
    @PostMapping("all")
    public String all(@RequestParam MultiValueMap<String, String> parameters ,
                      @RequestBody String xx , HttpServletRequest httpServletRequest){
        printQueryString(logger , httpServletRequest);

        printParams(logger , httpServletRequest);

        printHeaders(logger , httpServletRequest);

        parameters.forEach((k,v)->logger.info(k + "-------" + v));

        printBody(logger , xx);

        return "success";
    }


}
